<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            display: flex;
        }

        li {
            background-color: aqua;
            color: red;
            padding: 10px 15px;
        }

        li.action {
            background-color: red;
            color: aqua;
        }

        .box {
            position: relative;
        }

        .box>div {
            height: 300px;
            border: 1px solid #000;
            display: none;
        }

        .box>div.action {
            display: block;
        }
    </style>
</head>

<body>
    <ul>
        <li class="action">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="box">
        <div class="action">内容1111</div>
        <div>内容2222</div>
        <div>内容3333</div>
        <div>内容4444</div>
    </div>
    <script>
        /* 
       需求：
         点击按钮，点击谁，谁变色，其余的按钮颜色清空
       排他思想: 先清空所有， 留下我自己
       */
        let lis = document.querySelectorAll('li'); // 查询li标签
        let divs = document.querySelector('.box').querySelectorAll('div');

        for (let i = 0; i < lis.length; i++) {
            // 添加索引号
            lis[i].setAttribute('index', i);
            // 给每个按钮绑定点击事件
            lis[i].onmouseover = function () { // onmouseover 鼠标移上
                // 先清空所有按钮的背景
                for (let j = 0; j < lis.length; j++) {
                    lis[j].className = ''; // 
                }
                // 当前li样式改变
                this.className = "action";
                let index = this.getAttribute('index');
                for (let j = 0; j < divs.length; j++) {
                    divs[j].style.display = 'none';
                }
                //  留下我自己

                divs[index].style.display = 'block';
            }

        }
    </script>
</body>

</html>